/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

package edu.gatech.teama.doctorsoffice.net;

import edu.gatech.teama.doctorsoffice.server.DataModel;

import edu.gatech.teama.doctorsoffice.model.User;

/**
 * 
 * @author Team A
 * @version 1.0
 *
 */
public class AddUserMessage extends Message {

	/**
	 * <code>User</code> to be added
	 */
	private final User user;

	/**
	 * Hashed password of the new <code>User</code>
	 */
	private final String passwordHash;

	/**
	 * Initialize an AddUserMessage with a specified <code>User</code>
	 * and password hash
	 * @param u <code>User</code> to add
	 * @param passwordHash hash of user's password
	 */
	public AddUserMessage(User u, String passwordHash) {
		super(new Object[]{u, passwordHash});
		// TODO Auto-generated constructor stub
		this.user = u;
		this.passwordHash = passwordHash;
	}

	/**
	 * Add the user to the data model
	 * @param model data model to modify
	 * @return a <code>SuccessMessage</code> indicating the action's success
	 */
	@Override
	public Message handle(final DataModel model) {
		model.addUser(user, passwordHash);
		return new SuccessMessage(true);
	}

	@Override public String toString() { // $codepro.audit.disable methodJavadoc
		return user + " " + passwordHash;
	}

}
